package config

import (
	"github.com/sirupsen/logrus"
	"go-blockchain-from-scratch/utils"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

type Config struct {
	MongoDB *mongoDB `yaml:"MongoDB"`
}

type mongoDB struct {
	Host string `yaml:"host"`
	Port int    `yaml:"port"`
}

var Configs = InitConfig()

func InitConfig() *Config {
	yamlFile, err := ioutil.ReadFile(utils.GetConfigPath("/config.yml"))
	//logrus.Info(utils.GetConfigPath("config.yml"))
	if err != nil {
		logrus.Error(err)
	}
	var configs *Config
	if err := yaml.Unmarshal(yamlFile, &configs); err != nil {
		logrus.Error(err)
	}
	return configs

}
